package com.ruoyi.back.service.impl

import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.ruoyi.app.common.Data
import com.ruoyi.app.common.Ok
import com.ruoyi.back.domain.UrlShare
import com.ruoyi.back.mapper.UrlShareMapper
import com.ruoyi.back.service.UrlShareService
import org.springframework.stereotype.Service

@Service
class UrlShareServiceImpl : ServiceImpl<UrlShareMapper, UrlShare>(), UrlShareService {

    override fun saveUrlShare(urlShare: UrlShare): Data<Boolean> =
        urlShare.id?.run {
            Ok("更新链接分享成功", updateById(urlShare))
        } ?: Ok("保存链接分享成功", save(urlShare))

    override fun getUrlShare(): Data<UrlShare> = Ok(
        "获取链接分享成功", getOne(
            KtQueryWrapper(UrlShare::class.java)
        )
    )
}